<% 
  var headContent = {
%>
  <!-- //这里包含需要引入的其他css/js文件 -->
  <style>
   /*验证：提示信息样式 begin*/
   .am-alert-danger {
      background-color: transparent;
      border-color: transparent;
      color: red;
    }
    .am-alert {
      margin-bottom: 1em;
      padding: .625em;
      background: transparent;
      border: none;
      border-radius: 0;
    }
    /*验证：提示信息样式 end*/

    /*sku表格样式*/
    #tablediv>table>thead>tr>th,#tablediv>table>tbody>tr>td{
      width:10%;
    }
    #tablediv>table>tbody>tr>td>input{
      width:8rem;
    }

    /*附件上传*/
    .am-progress-xs {
      height: .2rem;
    }
    .am-progress {
      margin-bottom: 0;
    }
   /*附件上传 end*/

  /*注意提示信息*/
  .alert-msg-warning-style{
    background-color: #F37B1D;
    border-color: #e56c0c;
    color: #fff;
  }
  .alert-msg-primary-style{
    background-color: #5eb95e;
    border-color: #4bad4b;
    color: #fff;
  }
</style>
<%};%>

<%layout("/common/_layout.html",{head:headContent}){%>
  <!--模态窗口html代码位置-->
  <%include("promotion_input_modal.tpl"){}%>
  <form class="am-form" id="frm" name="frm" method="post" action="${base}/knowledgeBase/save" >
        <div class="am-cf am-padding">
          <div class="am-fl am-cf" onclick="javascript: History.back();"><strong class="am-text-primary am-text-lg">知识库管理</strong> / <small><%if(knowledgeBase.id!"" == ""){%>新增<%}else{%>编辑<%}%></small></div>
        </div>
    
        
        <div class="am-tabs am-margin" data-am-tabs>
          <ul class="am-tabs-nav am-nav am-nav-tabs">
            <li class="base-info am-active" id="base-info"><a href="#info">知识库详情</a></li>
            
          </ul>
          <div class="am-tabs-bd">
            <div class="am-tab-panel am-hide" id="category">
              <%include("product_input_category.tpl"){}%>
            </div>
            <div class="am-tab-panel am-active" id="info">
              <%include("knowledge_input_baseinfo.tpl"){}%>
            </div> 
          </div>
        </div>
        <!--选项卡（tabs）end-->
        <div class="am-margin am-active" id="submit-btns">
          <button type="submit" class="am-btn am-btn-primary am-btn-xs" id="submit">提交保存</button>
          <button type="button" class="am-btn am-btn-warning am-btn-xs" onclick="javascript: History.back();">返回上一级</button>
        </div>
        
        <div id="frmDiv" style="height:auto;">
        </div>
    
  </form>
  
  <link rel="stylesheet" href="${base}/template/common/css/datetimepicker/amazeui.datetimepicker.css"/>
  <script type="text/javascript" src="${base}/template/common/js/datetimepicker/amazeui.datetimepicker.js"></script>
  <script type="text/javascript" src="${base}/template/common/js/datetimepicker/locales/amazeui.datetimepicker.zh-CN.js" charset="UTF-8"></script>
  <script type="text/javascript" src="${base}/template/admin/js/utils.js"></script>
  <script src="${base}/template/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>



  <script type="text/javascript">
    var base = "${base}";
    var getCitySelectVal = function(){

        var city_ids = $("#city_select").val();
        $("#city_ids").val(city_ids);
    }

    $(function () {

        $("#enabled").val("1");
        var $mycheckbox = $('.switch-button');
        $mycheckbox.each(function() {
            $("#switch").on({
                'switchChange.bootstrapSwitch' : function(event, state) {
                    if (state.toString() == "true") {
                        $("#enabled").val("1");
                    } else {
                        $("#enabled").val("0");
                    }
                }
            });
        });


        getCitySelectVal();
        $("#submit").on("click", function () {
            var details = $("#detail").val();
            details = encodeURI(details)//details.replace(/\n/g,"#%#")
            $("#detail").val(details)
            $("#frm").submit();
        });



        $("#frm").validator({
            // 域通过验证时回调
            onValid: function (validity) {
                $(validity.field).closest('.am-form-group').find('.am-alert').hide();
            },
            // 验证出错时的回调， validity 对象包含相关信息，格式通 H5 表单元素的 validity 属性
            onInValid: function (validity) {
                var $field = $(validity.field);

                var field_id = $field.attr('id');

                var $group = $field.closest('.am-form-group');
                var $alert = $group.find('.am-alert');

                // 使用自定义的提示信息 或 插件内置的提示信息
                var msg = $field.data('validationMessage') || this.getValidationMessage(validity);

                if(field_id=="tariffClassName"){
                    msg = myMsg;
                }
                if (!$alert.length) {
                    $alert = $("<div class='am-alert am-alert-danger'></div>").hide().appendTo($group.find(".input-msg"));
                }
                console.log("onInValid : " + $field.val());
                $alert.html(msg).show();
            },
            //自定义验证
            validate: function (validity) {
                /**
                 * 校验资费大类名称唯一性
                 */
                var validityNameUnique = function(){
                    var tariffClassName = $("#tariffClassName").val();
                    var params = {tariffClassName:tariffClassName,tariffClassId:$("#tariffClassId").val()};
                    if(tariffClassName && tariffClassName.trim().length>1){
                        $.ajax({
                            type: "post",
                            url: "../tariffClass/validityCodeUnique",
                            data: params,
                            dataType: "json",
                            async:false,
                            success: function(data) {
                                if(data.resultCode != 1000){
                                    myMsg = "业务大类名称已存在";
                                    validity.valid = false;
                                }else{
                                    validity.valid = true;
                                }
                            },
                            error : function(textStatus) {
                                validity.valid = false;
                            }
                        });
                    }else{
                        myMsg = "大类名称不能为空";
                        validity.valid = false;
                    }
                };
                if ($(validity.field).is('#tariffClassName')) {
                    validityNameUnique();
                };
            }
        });














    });
  </script>
<%}%>